<template>
  <el-dialog
    title="提醒"
    width="400px"
    :visible.sync="visible"
    append-to-body
    :before-close="beforeClose"
  >
    <div class="error-msg" style="color:#7F848B;">
      导入成功
      <span style="color:#4AAE5F;">{{ successSize }}</span>
      条，失败
      <span style="color:#FF3B30;">{{ failSize }}</span>
      条，已更新员工信息
    </div>
    <div class="error-fail-title">失败原因：</div>
    <div class="error-fail-list">
      <div v-for="(item, index) in failList" :key="index" class="error-fail-msg">
        {{ index === 3 ? '...' : `${index + 1}. ${item}` }}
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="downloadError">下载失败记录</el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        successSize: 10,
        failSize: 10,
        failList: [],
        visible: false,
      };
    },
    methods: {
      open(data) {
        const { successSize, failSize, failList } = data;
        this.visible = true;
        this.successSize = successSize;
        this.failSize = failSize;
        this.failList = failList.length > 3 ? failList.slice(0, 4) : failList;
      },
      cancel() {
        this.visible = false;
        this.successSize = 0;
        this.failSize = 0;
        this.failList = [];
      },
      downloadError() {
        this.cancel();
        this.$emit('on-download-error');
      },
      beforeClose(done) {
        this.$emit('on-close');
        done();
      },
    },
  };
</script>

<style lang="scss" scoped>
  .error-msg {
    padding: 8px 0;
    color: #7f848b;
  }
  .error-fail-title {
    color: #7f848b;
    padding: 8px 0;
  }
  .error-fail-list {
    color: #ff3b30;
    padding: 5px 0;
  }
  // .error-fail-list
</style>
